<?php


namespace Part19_CombinationMode\Code2;

/**
 * 具体公司类
 */
class ConcreteCompany extends Company
{

    private $list;

    /**
     * @inheritDoc
     */
    public function add($c)
    {
        $this->list[] = $c;
    }

    /**
     * @inheritDoc
     */
    public function remove($c)
    {
        $key = array_search($c, $this->list, true);
        if ($key) {
            unset($this->list[$key]);
        } else {
            echo '移除元素失败' . "\n";
        }
    }

    /**
     * @inheritDoc
     */
    public function display($depth)
    {
        echo str_repeat('-', $depth) . $this->name . "\n";

        foreach ($this->list as $child) {
            $child->display($depth + 2);
        }
    }

    public function lineOfDuty()
    {
        foreach ($this->list as $child) {
            $child->lineOfDuty();
        }
    }
}